/**
 * @description 支付信息编辑弹窗
 * @author 李艳
 */

import React, {Component} from 'react'
import {Form, Input, Modal, Tabs, InputNumber} from 'antd';
import StandardModal from "../../../commons/components/StandardModal";
import {bankCategoryConfig, bankConfig, featureConfig} from "../../../configs/CommonComponentsConfig";
import SearchTable from "../../../commons/components/SearchTable";
import {savePaymentInfo} from "../service";

const FormItem = Form.Item;

class PayInfoModal extends Component {
  constructor(props) {
    super(props);
    this.state={
      bank:{}
    }
  }

  handleClose = () => {
    this.props.form.resetFields();
  };
  getPaymentInfo=(params)=>{
    let result=null;
    const {bank={}}=this.state;
      this.props.form.validateFieldsAndScroll((err,values)=>{
        if(!err){
          result=values;
          result.bank=bank
        }
      });

    return result
  };
  componentDidMount() {
    this.props.onRef(this);
  }
  bankAccountNumberValidator=(rule, value, callback)=>{
    let trimp = /[^0-9a-zA-Z\*\/_-]/;
    if (trimp.test(value))
      callback("请输入正确的银行账号");
    callback();
  };
  handleBankChange = (bank) => {
    this.setState({bank})
  };
  render() {
    const formItemLayout = {
      labelCol: {
        span: 7
      },
      wrapperCol: {
        span: 14
      },
    };

    const {confirmLoading, modalVisible, handleOk, handleCancel, defaultValue={}, isAdd,personnel} = this.props;
    const {getFieldDecorator,getFieldValue} = this.props.form;
    let title = "新增";
     let FormValue = defaultValue;
    if (!isAdd) {
      title = "编辑";
    }
    //let bankCategoryId = this.props.form.getFieldValue("bankCategoryId") || "";
    return (
      <StandardModal title={title}
                     visible={modalVisible}
                     onOk={handleOk}
                     onCancel={handleCancel}
                     width={600}
                     afterClose={this.handleClose}
                     confirmLoading={confirmLoading}
                     maskClosable={false}
      >
        <FormItem
          style={{display: "none"}}
          label="id">
          {getFieldDecorator('id', {
            initialValue: FormValue.id ? FormValue.id : null,
          })(
            <Input/>
          )}
        </FormItem>
        <FormItem
          style={{display: "none"}}
          {...formItemLayout}
          label="receiverType">
          {getFieldDecorator('receiverType', {
            initialValue: "H",
          })(
            <Input/>
          )}
        </FormItem>
        <FormItem
          style={{display: "none"}}
          {...formItemLayout}
          label="receiverId">
          {getFieldDecorator('receiverId', {
            initialValue: personnel ? personnel.receiverId : null,
          })(
            <Input/>
          )}
        </FormItem>
        <FormItem
          style={{display: "none"}}
          {...formItemLayout}
          label="receiverCode">
          {getFieldDecorator('receiverCode', {
            initialValue: personnel ? personnel.receiverCode : "",
          })(
            <Input/>
          )}
        </FormItem>
        <FormItem
          style={{display: "none"}}
          {...formItemLayout}
          label="receiverName">
          {getFieldDecorator('receiverName', {
            initialValue: personnel ? personnel.receiverName : "",
          })(
            <Input/>
          )}
        </FormItem>
        <FormItem
          style={{display: "none"}}
          {...formItemLayout}
          label="tenantCode">
          {getFieldDecorator('tenantCode', {
            initialValue: personnel ? personnel.tenantCode : "",
          })(
            <Input/>
          )}
        </FormItem>
        <FormItem
          style={{display: "none"}}
          {...formItemLayout}
          label="display">
          {getFieldDecorator('display', {
            initialValue: personnel ? personnel.display : "",
          })(
            <Input/>
          )}
        </FormItem>
        <FormItem
          {...formItemLayout}
          label="银行类别"
        >
          {getFieldDecorator('bankCategoryId', {
            initialValue: personnel.bank?personnel.bank.bankCategoryId:null,
            rules: [{required: true, message: '请选择银行类别'}]
          })(
            <SearchTable config={bankCategoryConfig} initValue={false}/>
          )}
        </FormItem>
        <FormItem
          {...formItemLayout}
          label="银行"
        >
          {getFieldDecorator('bankId', {
            initialValue: personnel.bankId?personnel.bankId:null,
            rules: [{required: true, message: '请选择银行'}]
          })(
            <SearchTable config={bankConfig} initValue={false}
                         // params={{Q_EQ_bankCategoryId:bankCategoryId}}
                         params={{bankCategoryId:getFieldValue("bankCategoryId")}}
                         selectChange={this.handleBankChange}/>
          )}
        </FormItem>
        <FormItem
          {...formItemLayout}
          label="银行账号">
          {getFieldDecorator('bankAccountNumber', {
            initialValue: personnel.bankAccountNumber?personnel.bankAccountNumber:"",
            rules: [{required: true, message: '请填写银行账号',whitespace:true}, {validator: this.bankAccountNumberValidator}]
          })(
            <Input maxLength={40}/>
          )}
        </FormItem>
        <FormItem
          {...formItemLayout}
          label="排序">
          {getFieldDecorator('rank', {
            initialValue: personnel.rank&&personnel.rank>=0?personnel.rank:0,
          })(
            <InputNumber precision={0} min={0} max={9999999999} style={{width:"100%"}}/>
          )}
        </FormItem>
      </StandardModal>
    );
  }
}

PayInfoModal = Form.create()(PayInfoModal);
export default PayInfoModal;
